package com.tt.plat8.bootstrap;

import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;

public class BorderLayout extends HorizontalLayout {

	private static final long serialVersionUID = -1927093002228887069L;

	private boolean hasEast;

	private boolean hasWest;

    public BorderLayout(){
        setSizeUndefined();
    }

	public void addComponent(Component component, Position position) {
		if (Position.EAST == position) {
			addEastPanel(component);
		} else if (Position.WEST == position) {
			addWestPanel(component);
		} else if (Position.CENTER == position) {
			addCenterPanel(component);
		} else {
			throw new IllegalArgumentException();
		}
	}

	public void removeComponent(Position position) {
		if (position == Position.WEST && hasWest) {
			removeComponent(getComponent(0));
		} else if (position == Position.EAST && hasEast) {
			removeComponent(getComponent(getComponentCount() - 1));
		}
	}

	private void addCenterPanel(Component component) {
		addComponent(component);
		setExpandRatio(component, 1f);

	}

	private void addEastPanel(Component component) {
		addComponent(component);
        setExpandRatio(component,5.5f);
		hasEast = true;
	}

	private void addWestPanel(Component component) {
		addComponent(component, 0);
        setExpandRatio(component,1);
		hasWest = true;
	}

	public static enum Position {
		EAST, WEST, CENTER
	}

}
